package project

import (
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"google.golang.org/grpc/resolver"
	"log"
	"test.com/project-api/config"
	"test.com/project-common/discovery"
	"test.com/project-common/logs"
	project "test.com/project-grpc/project"
)

var ProjectServiceClient project.ProjectServiceClient

// InitRpcProjectClient 初始化用户RPC客户端
func InitRpcProjectClient() {
	// 创建Etcd注册器
	etcdRegister := discovery.NewResolver(config.AppConf.EtcdConfig.Addrs, logs.LG)
	// 注册Etcd解析器
	resolver.Register(etcdRegister)
	// 建立与Etcd的连接
	conn, err := grpc.Dial("etcd:///project", grpc.WithTransportCredentials(insecure.NewCredentials()))
	// 设置 Unary 客户端拦截器
	// grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	// 创建登录服务客户端
	ProjectServiceClient = project.NewProjectServiceClient(conn)
}
